
package com.core.util;

import android.app.Activity;

import com.google.analytics.tracking.android.EasyTracker;
import com.umeng.analytics.MobclickAgent;

/**
 *  [简要描述]:GA统计
 *  [详细描述]:
 *  @author [allenwang]
 *  @email  [allen.wang@b5m.com]
 *  @version    [版本号,Oct 21, 2013]
 *  @see        [DataTracker]
 *  @package    [com.b5m.afw.internal]
 *  @since  [afw]
 */
public class B5MDataTracker
{
    private static String category = "NGNZ";
    private static String channel = "渠道";

    public static void onStart(Activity activity)
    {
        if (activity != null)
            EasyTracker.getInstance().activityStart(activity);
    }

    public static void onStop(Activity activity)
    {
        if (activity != null)
            EasyTracker.getInstance().activityStop(activity);
    }

    public static void uploadChannel(String label)
    {
        EasyTracker.getTracker().set(channel, label);
    }

    public static void sendEvent(String action , String label)
    {
        if (action.length() > 0 && label.length() > 0)
        {
            EasyTracker.getTracker().sendEvent(getCategroy(), action, label, (long) 1);
        }
    }

    public static void onPageStart(String trackString)
    {
        if (trackString.length() > 0)
        {
            EasyTracker.getTracker().sendView(trackString);
            MobclickAgent.onPageStart(trackString);
        }
    }

    public static void onPageEnd(String trackString)
    {
        if (trackString.length() > 0)
        {
            //            EasyTracker.getTracker().sendView(trackString);
            MobclickAgent.onPageEnd(trackString);
        }
    }

    public static void setCategory(String categoryString)
    {
        category = categoryString;
    }

    private static String getCategroy()
    {
        return (category != null) ? category : "";
    }
}
